package com.sean.activity;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;

import com.sean.MyApplication;
import com.sean.R;

public class MainActivity extends ActivityGroup {
	
	public static final String TAG = "MainActivity";
	
	private LinearLayout mMainLayout;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setTheme(android.R.style.Theme_NoTitleBar);
        ((MyApplication)this.getApplication()).setMainActivity(this);
        setContentView(R.layout.main);
        mMainLayout = (LinearLayout)this.findViewById(R.id.mainLayout);
        Log.e(TAG, "onCreate...");
        
        Intent intent = new Intent();
        intent.setClass(this, MyActivity.class);
        startActivityInFramework(intent);
        
    }

	@Override
	protected void onDestroy() {
		Log.e(TAG, "onDestroy...");
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		Log.e(TAG, "onPause...");
		super.onPause();
	}

	@Override
	protected void onRestart() {
		Log.e(TAG, "onRestart...");
		super.onRestart();
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		Log.e(TAG, "onRestoreInstanceState...");
		super.onRestoreInstanceState(savedInstanceState);
	}

	@Override
	protected void onResume() {
		Log.e(TAG, "onResume...");
		super.onResume();
	}

	@Override
	protected void onStart() {
		Log.e(TAG, "onStart...");
		super.onStart();
	}
	
	@Override
	protected void onStop() {
		Log.e(TAG, "onStop...");
		super.onStop();
	}
	
	public void startActivityInFramework(Intent intent) {
		String id = intent.getComponent().getClassName();
		this.getLocalActivityManager().removeAllActivities();
		View view = this.getLocalActivityManager().startActivity(id, intent).getDecorView();
		mMainLayout.removeAllViews();
		mMainLayout.addView(view, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
	}

}